package cn.exrick.xboot.modules.webserviceSMS.call;

import cn.exrick.xboot.common.jiuqiCommon.callAPIUtil.CallApiUtil;
import cn.exrick.xboot.modules.webserviceSMS.server.WsSmsService;
import cn.exrick.xboot.modules.webserviceSMS.server.WsSmsServiceServiceLocator;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;

import javax.xml.rpc.ServiceException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;

@Slf4j
public class MASsendSms {

    public static void main(String[] args) throws Exception {

        WsSmsServiceServiceLocator locator=new WsSmsServiceServiceLocator();
        WsSmsService wsSmsServicePort = locator.getWsSmsServicePort();
        String s = wsSmsServicePort.sendSms("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                "<WsSubmitReq>\n" +
                "  <apId>admin</apId>\n" +
                "  <secretKey>%5a%sJu8</secretKey>\n" +
                "  <ecName>【湖南交水建集团】</ecName>\n" +
                "  <mobiles>\n" +
                "    <string>15145299919</string>\n" +
                "    <string>15145299919</string>\n" +
                "  </mobiles>\n" +
                "  <content>TEST内容</content>\n" +
                "  <sign>CH6FsWGih</sign>\n" +
                "  <addSerial></addSerial>\n" +
                "  <mac>a53c037a6d4698fd8ff418fba67ec4d9</mac>\n" +
                "</WsSubmitReq>");
        System.out.println(s);

        String md5 = MASsendSms.getMd5("【湖南交水建集团】" + "admin" + "%5a%sJu8" + "15145299919" + "TEST内容" + "CH6FsWGih" + "");
        log.info("md5:"+md5);

        /**
         * http方式调用
         */
        /*String json="{\"ecName\":\"政企分公司测试\", \"apId\":\"demo0\", \"mobiles\":\"13800138000\", \"content\":\"移动改变生活。\", \"sign\":\"DWItALe3A\", \"addSerial\":\"\", \"mac\":\"7997ddb079db2155b517b21b2a812370\"}";
        JSONObject jSONObject = JSONObject.parseObject(json);
        CallApiUtil call= new CallApiUtil();
        JSONObject jsonObject = call.doPostGetJson(jSONObject, "http://112.35.1.155:1992/sms/norsubmit");
        log.info("返回报文"+jsonObject);*/

    }
    public static String getMd5(String string) {
        try {
            //MessageDigest md5 = MessageDigest.getInstance("湖南省交通水利建设集团有限公司"+"admin"+"%5a%sJu8"+"15145299919"+"TEST内容"+"CH6FsWGih"+"");
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            byte[] bs = md5.digest(string.getBytes("UTF-8"));
            StringBuilder sb = new StringBuilder(40);
            for (byte x : bs) {
                if ((x & 0xff) >> 4 == 0) {
                    sb.append("0").append(Integer.toHexString(x & 0xff));
                } else {
                    sb.append(Integer.toHexString(x & 0xff));
                }
            }
            return sb.toString();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}

